package com.ruoyi.feign;

import com.ruoyi.entity.MessageRequest;
import com.ruoyi.entity.MessageResponse;
import com.ruoyi.feign.fallback.NtfyServiceClientFallback;
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import io.github.resilience4j.retry.annotation.Retry;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

// name指定要调用的服务名称（在Nacos中注册的服务名）
@FeignClient(name = "middle", fallback = NtfyServiceClientFallback.class)
public interface NtfyServiceClient {
    
    // 假设目标服务有一个获取数据的接口
    @Retry(name = "mot-retry")
    @CircuitBreaker(name = "mot-circuit-breaker")
    @GetMapping("/api/temperature/send")
    @ResponseBody
    String sendTemperature();

    @Retry(name = "mot-retry")
    @CircuitBreaker(name = "mot-circuit-breaker")
    @GetMapping("/api/data")
    @ResponseBody
    String getData();

    @Retry(name = "mot-retry")
    @CircuitBreaker(name = "mot-circuit-breaker")
    @PostMapping("/api/message/ntfy")
    @ResponseBody
    MessageResponse sendNtfyMessage(@RequestBody MessageRequest request);
}